package se.liu.oschi129.game.objects.enemies.projectiles;

import java.util.Random;

import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.objects.WorldObject;

/**
 * This is a vegetable projectile
 * 
 * @author oschi129
 */
public class ObjectEnemyProjectile01 extends ObjectEnemyProjectile {
	
	// A random picture generator
	private Random imageGenerator = new Random();
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public ObjectEnemyProjectile01(WorldObject target, double x, double y) {
		super(Type.SOFT, target, x,y,16,16);
		String imageName = "img_projectile0" + (1 + imageGenerator.nextInt(3));
		setAnimation(AnimationSpace.get(imageName));
		setVisible(true);
		double direction = Math.atan2(target.getY() - y - 128, target.getX() - x);
		setHorizontalSpeed(Math.cos(direction) * 8);
		setVerticalSpeed(Math.sin(direction) * 16);
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	@Override public void performStepAction(World world) {
		super.performStepAction(world);
		if (getPhysicalRules() == null) {
			setPhysicalRules(world.getPhysicalRules());
			setVerticalAcceleration(getPhysicalRules().getGravity());
		}
		if (getY() > world.getHeight())
			world.removeObjectSynchronized(this);
	}
	
}
